//
//  CZStatusForwardCell.swift
//  swiftweibo
//
//  Created by Apple on 15/11/29.
//  Copyright © 2015年 tzw. All rights reserved.
//

import UIKit
// 转发微博cell
class CZStatusForwardCell: CZStatusCell {
    
    override var status: CZStatus?{
        didSet{
        let name = status?.retweeted_status?.user?.screen_name ?? "被转发的用户不存在....."
        let retweetText = status?.retweeted_status?.text ?? "被转发的内容为空..."
            forwardLabel.text = "@" + name + ":" + retweetText
        }
    }

    // 刷新UI
    override func prepareUI(){
        // 调用父类的
        super.prepareUI()
        // 添加
        // 添加子类特有的空间
        contentView.insertSubview(bkgButton, atIndex: 0)
        contentView.addSubview(forwardLabel)
        //约束
        // contentLabel的垂直左下,在bottomView垂直方向的右上
        bkgButton.ff_AlignVertical(type: ff_AlignType.BottomLeft, referView: contenLabel, size: nil, offset: CGPoint(x: -CZStatusCellMargin, y: CZStatusCellMargin))
        bkgButton.ff_AlignVertical(type: ff_AlignType.TopRight, referView:bottomView , size: nil, offset: CGPoint(x: 0, y: 0))
        
        // 约束label
        forwardLabel.ff_AlignInner(type: ff_AlignType.TopLeft, referView: bkgButton, size: nil, offset: CGPoint(x: CZStatusCellMargin, y: CZStatusCellMargin))
        // 宽度约束
        contentView.addConstraint(NSLayoutConstraint(item: forwardLabel, attribute: NSLayoutAttribute.Width, relatedBy: NSLayoutRelation.Equal, toItem: nil, attribute: NSLayoutAttribute.NotAnAttribute, multiplier: 1, constant: UIScreen.mainScreen().bounds.width - 2 * CZStatusCellMargin))
        // 配图视图约束
        let con = pictureView.ff_AlignVertical(type: ff_AlignType.BottomLeft, referView: forwardLabel, size: CGSize(width: 290, height: 290), offset: CGPoint(x: 0, y: CZStatusCellMargin))
        pictureViewWidthCon = pictureView.ff_Constraint(con, attribute: NSLayoutAttribute.Width)
        pictureViewHeightCon = pictureView.ff_Constraint(con, attribute: NSLayoutAttribute.Height)
    }
    // MARK: - 懒加载
    // 背景按钮
    private lazy var bkgButton: UIButton = {
        let button = UIButton()
        // 背景颜色
        button.backgroundColor = UIColor(white: 0.8, alpha: 1)
        return button
    }()
    // Label，显示文字
    private lazy var forwardLabel: UILabel = {
       let label = UILabel(color: UIColor.lightGrayColor(), fontSize: 14)
        label.numberOfLines = 0
        return label
    }()
}
